﻿using Coolzon.UI.Core.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RT = Coolzon.Metadata.Runtime;

namespace Coolzon.UI.Core.Converters
{
    public class DataSeriesFilterConverter : ValueConverter
    {
        public object Convert(ConvertContext context, RT.Property property)
        {
            DataSeriesFilter dataFilter = new DataSeriesFilter();
            string value = string.IsNullOrEmpty(property.ValueString) == false? property.ValueString:property.ValueNode.GetAtrributeValue("Value");
            if (!string.IsNullOrWhiteSpace(value))
            {
                dataFilter.InitByText(value);
            }
            return dataFilter;
        }

        public RT.ValueNode ConvertBack(ConvertContext context, object value, object dtTagData)
        {
            RT.ValueNode valueNode = new RT.ValueNode("DataFilter");
            valueNode.Attributes = new Dictionary<string, string>();
            valueNode.Attributes.Add("Value", System.Convert.ToString(value));
            return valueNode;
        }
    }
}
